using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization;
using System.Security.Permissions;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
    
namespace Codex
{
    public class FieldTag : IComparable, IComparer, IXmlSerializable
    {
        private string fieldName, fieldValue;

        public FieldTag()
        {
            fieldName = "";
            fieldValue = "";
        }

        public FieldTag(string _fieldName)
        {
            fieldName = _fieldName;
            fieldValue = "";
        }

        public FieldTag(string _fieldName, string _fieldValue)
        {
            fieldName = _fieldName;
            fieldValue = _fieldValue;
        }

        public string getFieldName() { return fieldName; }
        public string getFieldValue() { return fieldValue; }
        
        public void setFieldName(string _fieldName) { fieldName = _fieldName; }
        public void setFieldValue(string _fieldValue) { fieldValue = _fieldValue; }


        public XmlSchema GetSchema()
        {
            return null;
        }

        public void WriteXml(XmlWriter w)
        {
            w.WriteAttributeString("FieldName", fieldName);
            w.WriteAttributeString("FieldValue", fieldValue);
        }

        public void ReadXml(XmlReader r)
        {
            fieldName = r.GetAttribute("FieldName");
            fieldValue = r.GetAttribute("FieldValue");
            r.Read();
        }


        public int CompareTo(Object compareObject)
        {
            if (compareObject is FieldTag)
            {
                FieldTag compareField = (FieldTag)compareObject;

                return (int)(this.fieldName.CompareTo(compareField.getFieldName()));
            }
            else
            {
                throw new ArgumentException("object is not a Field");
            }
        }

        public int Compare(Object compareObject1, Object compareObject2)
        {
            if (compareObject1 is FieldTag && compareObject2 is FieldTag)
            {
                FieldTag compareTag1 = (FieldTag)compareObject1;
                FieldTag compareTag2 = (FieldTag)compareObject2;

                return compareTag1.CompareTo(compareTag2);
            }
            else throw new ArgumentException("one of two objects being compared is not a NetNode");
        }

        public override string ToString()
        {
            return fieldName + ": " + fieldValue;
        }
    }
}
